﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace CoreLib
{
    public class CCameraComponent:CDynamicComponent
    {
        private float speed;

        public float Speed
        {
            get { return speed; }
            set { speed = value; }
        }
        private Matrix view;

        public  Matrix View
        {
            get { return view; }
            set { view = value; }
        }


        private float nearPlane;
        public float NearPlane
        {
            get { return nearPlane; }
            set { nearPlane = value; }
        }
        private float farPlane;
        public float FarPlane
        {
            get { return farPlane; }
            set { farPlane = value; }
        }

        public Vector3 ChasePosition
        {
            get { return chasePosition; }
            set { chasePosition = value; }
        }
        private Vector3 chasePosition;
        /// <summary>
        /// Direction the chased object is facing.
        /// </summary>
        public Vector3 ChaseDirection
        {
            get { return mChaseDirection; }
            set { mChaseDirection = value; }
        }
        public Vector3 mChaseDirection;
        static Matrix projection;
        public static Matrix Projection
        {
            get
            {
                float aspectRatio = (float)Engine.graphics.GraphicsDevice.Viewport.Width /
                               (float)Engine.graphics.GraphicsDevice.Viewport.Height;
                Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                        aspectRatio,
                                                                        NearPlaneDistance,
                                                                         FarPlaneDistance);
                return projection;
            }
            set { projection = value; }
        }
        /// <summary>
        /// Perspective aspect ratio. Default value should be overriden by application.
        /// </summary>
        public float AspectRatio
        {
            get { return aspectRatio; }
            set { aspectRatio = value; }
        }
        private float aspectRatio = 4.0f / 3.0f;

        /// <summary>
        /// Perspective field of view.
        /// </summary>
        public float FieldOfView
        {
            get { return fieldOfView; }
            set { fieldOfView = value; }
        }
        private float fieldOfView = MathHelper.ToRadians(45.0f);


        public static Viewport ViewPort
        {
            get { return Engine.graphics.GraphicsDevice.Viewport; }
           
        }

        /// <summary>
        /// Distance to the near clipping plane.
        /// </summary>
        public static float NearPlaneDistance
        {
            get { return nearPlaneDistance; }
            set { nearPlaneDistance = value; }
        }
        public static float nearPlaneDistance = 1.0f;

        /// <summary>
        /// Distance to the far clipping plane.
        /// </summary>
        public static float FarPlaneDistance
        {
            get { return farPlaneDistance; }
            set { farPlaneDistance = value; }
        }
        private static float farPlaneDistance = 10000.0f;

        public float TurnSpeed
        {
            get { return turnSpeed; }
            set { turnSpeed = value; }
        }
        private float turnSpeed = 0.01f;

        private Vector3 lookAt;

        public Vector3 LookAt
        {
            get { return lookAt; }
            set { lookAt = value; }
        }


        public CCameraComponent(Game game)
            : base(game)
        {
        }
    }
}
